<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/news.css"/>
    <style>
        .test{

        }
    </style>
</head>

<body class="childrenBody">
<blockquote class="layui-elem-quote news_search">
    <div class="layui-inline">
        <div class="layui-input-inline">
            <input type="text" value="" placeholder="关键字" class="layui-input search_input" id="sSearchKey">
        </div>

        <div class="layui-input-inline">
            <input class="layui-input" placeholder="开始日" id="startTime">
        </div>
        <div class="layui-input-inline">
            <input class="layui-input" placeholder="截止日" id="endTime">
        </div>

    </div>
    <a class="layui-btn layui-btn-primary" id="search"><i class="layui-icon">&#xe615;</i>查询</a>
    </div>
</blockquote>

<div class="left_list">

    <div id="test3" class="layui-inline">
        <a class="layui-btn layui-btn-normal newsAdd_btn" >订单导入</a>
    </div>

    <div class="layui-inline">
        <a class="layui-btn layui-btn-danger news_del" onclick="changeListItem(2)">批量删除</a>
    </div>
</div>
<form action="" class="layui-form table-box">

    <div id="listView"></div>
    <div id="laypage" class="laypage"></div>

</form>
<form class="layui-form" action="">
    <div id="courier" class="hide">

        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">登录密码</label>-->
            <!--<div class="layui-input-block">-->
                <!--<input type="text" name="title" width="400px" lay-verify="title" placeholder="请输入登录密码" class="layui-input"-->
                <!--&gt;-->
            <!--</div>-->
        <!--</div>-->

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">选择工人</label>
                <div class="layui-input-block">
                    <select  name="quiz" id="courierList">
                        <option value="0">请选择工人</option>

                    </select>
                </div>
            </div>

        </div>

    </div>
</form>

<input id="mid" value="" type="hidden"/>
<script type="text/javascript" src="/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="/js/time.js"></script>
<script src="/layui/layui.all.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/common.js" type="text/javascript" charset="utf-8"></script>
<script id="tmpList" type="text/html">

    <table class="layui-table" lay-even lay-skin="row">
        <thead>
        <tr>
            <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
            <th>订单ID</th>
            <th>买家会员名</th>
            <th>联系人姓名</th>
            <th>联系手机</th>
            <!--<th>收货地址</th>-->
            <th>买家留言</th>
            <!--<th>订单备注</th>-->
            <th>宝贝数量</th>
            <!--<th>修改后的收货地址</th>-->
            <th>安装工人</th>
            <th>支付方式</th>
            <th>订单类型</th>
            <th>订单状态</th>
            <th>创建时间</th>

            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {{# layui.each(d.list, function(index, item){ }}

        <tr>
            <td><input type="checkbox" value="{{ item.id }}" name="" lay-skin="primary"></td>
            <td>{{#if (item.id!=null) {}}
                {{ item.id }}
                {{#}}}
            </td>
            <td>{{#if (item.username!=null) {}}
                {{ item.username }}
                {{#}}}
            </td>
            <td>{{#if (item.linkname!=null) {}}
                {{ item.linkname }}
                {{#}}}
            </td>
            <td>{{#if (item.linkphone!=null) {}}
                {{ item.linkphone }}
                {{#}}}
            </td>
            <!--<td>{{#if (item.linkaddress!=null) {}}-->
                <!--{{ item.linkaddress }}-->
                <!--{{#}}}-->
            <!--</td>-->
            <td>{{#if (item.usermemo!=null) {}}
                {{ item.usermemo }}
                {{#}}}
            </td>
            <!--<td>{{#if (item.ordermemo!=null) {}}-->
                <!--{{ item.ordermemo }}-->
                <!--{{#}}}-->
            <!--</td>-->
            <td>{{#if (item.goodnum!=null) {}}
            {{ item.goodnum }}
            {{#}}}
        </td>
            <!--<td>{{#if (item.newaddress!=null) {}}-->
                <!--{{ item.newaddress }}-->
                <!--{{#}}}-->
            <!--</td>-->
            <td>
                {{#if (item.couriername!="") {}}
                {{ item.couriername }}
                {{#}}}
            </td>
            <td>{{#if (item.paytype==0) {}}
                未支付
                {{#}}}
                {{#if (item.paytype==1) {}}
                微信
                {{#}}}
                {{#if (item.paytype==2) {}}
                支付宝
                {{#}}}
                {{#if (item.paytype==3) {}}
                线下支付
                {{#}}}
            </td>
            <td>{{#if (item.ordertype==1) {}}
                安装
                {{#}}}
                {{#if (item.ordertype==2) {}}
                维修
                {{#}}}
            </td>
            <td>{{#if (item.status ==0) {}}
                待分配
                {{#}}}
                {{#if (item.status == 1){}}
                已分配 待确认
                {{#}}}
                {{#if(item.status ==2){}}
                已确认 待完成
                {{#}}}
                {{# if(item.status ==3){}}
                已完成
                {{#}}}
            </td>
            <td>{{formatDate(item.createTime)}}</td>


            <td>
                <a class="layui-btn layui-btn-mini news_details" onclick=detail({{item.id}})><i class="layui-icon">
                    &#xe642;</i>详情</a>
                {{#if(item.status == 0){}}
                <a class="layui-btn layui-btn-mini layui-btn-warm" onclick="test({{item.id}},{{item.courierid}})"><i
                        class="layui-icon">&#xe642;</i>派单</a>
                {{#}}}
                <a class="layui-btn layui-btn-mini layui-btn-normal news_edit" onclick=edit({{item.id}})><i
                        class="layui-icon">&#xe642;</i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-mini news_del" onclick=deletex({{item.id}})><i
                        class="layui-icon">&#xe640;</i>删除</a>
            </td>
        </tr>
        {{# }); }} {{# if(d.list.length === 0){ }}
        <td colspan="15" align="center">无数据</td>
        {{# } }}
        </tbody>
    </table>
</script>

<script>
    function getCourier(){
        $.ajax({
           url:'/courier/list',
           type:'POST',
           data:{

           } ,
           dataType:'json',
            success:function (data) {
               console.log(JSON.stringify(data));
                if(data.status == '0'){
                    for(var i=0;i<data.result.length;i++){
                        var op = document.createElement("option");
                        op.text = data.result[i].nickname;
                        op.value = data.result[i].id;
                        document.getElementById("courierList").appendChild(op);
                        console.log(op);
                    }
                    layui.form.render();
                }
                $('#courierList').val("4");
                layui.form.render();
                console.log("facao" +$('#courierList').val());
            }

        });
    }
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //开始时间
        laydate.render({
            elem: '#startTime'
        });
        //结束时间
        laydate.render({
            elem: '#endTime'
        });
    });

    layui.use('upload',function () {
        var upload = layui.upload;
        //指定允许上传的文件类型
        upload.render({
            elem: '#test3'
            ,url: '../..//file/upload'
            ,accept: 'file' //普通文件
            ,done: function(res){
                console.log(res);
                $.ajax({
                    type: "post",
                    url: "/courierorder/excelDl",
                    data: {
                        excelPath: res.result
                    },
                    dataType: "json",
                    success:function (data) {
                        console.log((JSON.stringify(data)));
                    }
                    
                    
                });
            }
        });
    });


    //批量操作
    function changeListItem(PL) {
        var box = $("input[lay-filter='allChoose']").prop("checked");
        var child = $("input[lay-filter='allChoose']").parents('table').find('tbody tr td:first-child input[type="checkbox"]:checked');
        var valueList = [];
        for (var i = 0; i < child.length; i++) {
            var item = parseInt(child.eq(i).attr("value"));
            valueList.push(item);
        }
        switch (PL) {
            default:
                deleteAll(valueList);
                break;
        }

    }

    //批量删除
    function deleteAll(Items) { //obj=整条数据行
        if (Items.length > 0) {
            layer.confirm('是否删除选中项？', {
                btn: ['是', '否'] //按钮
            }, function (index, layero) {

                for (var i = 0; i < Items.length; i++) {
                    $.ajax({
                        type: "post",
                        url: "/courierorder/delete",
                        data: {
                            courierorderId: Items[i]
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.status == 0) {
                                getList({});
                            } else {
                                layer.msg(data.msg, {
                                    icon: 1
                                });
                            }
                        }
                    });
                }
                layer.msg('删除成功', {
                    icon: 1
                });

                layer.close(index);

            }, function () {
            });
        } else {
            layer.msg('未选择无法操作！', {
                icon: 7
            });
        }
    }


    var searchData = {};
    $(document).ready(function () {
        getCourier();
        var status = GetQueryString("status");
        searchData = {
            status:status
        }


        $("#search").click(function () {
            searchData = {
                startTime: $('#startTime').val(),
                endTime: $('#endTime').val(),
                searchKey: $('#sSearchKey').val(),
                status:status
            };
            getList({});
        });
        getList({});
    });

    function getList(data) {
        data = searchData;
        CommonLoadList("/courierorder/list", data, page, "tmpList", "listView", "laypage");
    }

    //点击添加文章弹窗（小弹窗）
    // $(".newsAdd_btn").click(function () {
    //     var index = layui.layer.open({
    //         shade: 0, maxmin: true,
    //         title: "添加",
    //         type: 2,
    //         content: "courierorderOp.html?op=add",
    //         success: function (layero, index) {
    //             setTimeout(function () {
    //                 layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
    //                     tips: 3
    //                 });
    //             }, 500)
    //         }
    //     });
    //     layui.layer.full(index);
    // })

    function detail(id) {
        var index = layui.layer.open({
            shade: 0,maxmin:true,
            title: "详情",
            type: 2,
            area:['500px', '300px'],


            content: "courierorderOp.html?op=detail&id=" + id,
            success: function (layero, index) {
                setTimeout(function () {
                    layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500);
            }
        });
        layui.layer.full(index);
    }

    function setOrderCourier(id) {
        $.ajax({
            type:"post",
            url:"/courierorder/getOrderCourier",
            data:{
                id:id
            },
            dataType:"json",
            success:function (data) {
                if (data.status == 0) {
                    $('#courierList').val(data.result.id);
                    layui.use('form', function () {
                        layui.form.render('select');
                    });


                }else {
                    $('#courierList').val('0');
                    layui.use('form', function () {
                        layui.form.render('select');
                    });

                }
            }

        });
    }

    //点击添加文章弹窗（小弹窗）
function test(courierorderid,courierid) {
        console.log(courierorderid,courierid);
    setOrderCourier(courierid);

    layui.use('layer', function () {//独立版的layer无需执行这一句
        var indexlay;
        var layedit;
        var $ = layui.jquery,
            layer = layui.layer; //独立版的layer无需执行这一句
        layer.open({
            type: 1,
            title: '分配工人',
            area: ['800px', '600px'],
            content: $("#courier"),
            btn: ['提交', '关闭'],
            btnAlign: 'c',
            success: function (layero, index) {
                setOrderCourier(courierid);
            },
            yes: function (index, layero) {

                // if ($("#username").val() == "") {
                //     layer.msg('请输入登录账号', {icon: 2});
                //     return;
                // }

                $.ajax({
                    type: "post",
                    url: "/courierorder/setCourier",
                    data: {
                        courierid: $("#courierList").val(),
                        courierorderid:courierorderid
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.status == 0) {
                            $("#courier").hide();
                            getList({});
                            layer.close(index);
                            top.layer.msg("修改成功！");
                        } else {
                            layer.msg(data.msg, {icon: 1});
                        }
                    }
                });



            },
            btn2: function (index, layero) {
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
                $("#courier").hide();

            },
            cancel: function () {
                $("#courier").hide();
                //右上角关闭回调
                //return false 开启该代码可禁止点击该按钮关闭
            }
        });
    });
}

    function edit(id) {
        var index = layui.layer.open({
            shade: 0, maxmin: true,
            title: "编辑",
            type: 2,
            content: "courierorderOp.html?op=edit&id=" + id,
            success: function (layero, index) {
                setTimeout(function () {
                    layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500);
            }
        });
        layui.layer.full(index);
    }

    function deletex(id) {
        //点击删除按钮
        layer.confirm('是否删除？', {
            btn: ['是', '否'] //按钮
        }, function () {
            $.ajax({
                type: "post",
                url: "/courierorder/delete",
                data: {
                    courierorderId: id
                },
                dataType: "json",
                success: function (data) {
                    if (data.status == 0) {
                        layer.msg('删除成功', {
                            icon: 1
                        });
                        getList({});
                        layer.close(index);
                    } else {
                        layer.msg(data.msg, {
                            icon: 1
                        });
                    }
                }
            });
        }, function () {
        });
    }

    //状态开关
    layui.use('form', function () {
        var form = layui.form
    });
</script>
</body>
</html>